// pages/fenlei/fenlei.js
import * as API from "../../utils/config.js"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.yuanchuang(),
    this.qingnian(),
    this.shaonv(),
    this.shenmei()
  },
  //滑动切换
  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  //点击切换
  clickTab: function (e) {

    var that = this;

    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  leixing() {
    wx.request({
      url: API.category,
      data: {
        "key": API.key,
        // "type"
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          leixing: res.data.result
        })
        console.log(this.data.leixing)
      }
    })
  },
  yuanchuang() {
    wx.request({
      url: API.book,
      data: {
        "key": API.key,
        "type": "少年漫画"
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          manhua: res.data.result.bookList
        })
        console.log(this.data.manhua)
      }
    })
  },

  shaonv() {
    wx.request({
      url: API.book,
      data: {
        "key": API.key,
        "type": "少女漫画"
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          shaonv: res.data.result.bookList
        })
        console.log(this.data.manhua)
      }
    })
  },
  qingnian() {
    wx.request({
      url: API.book,
      data: {
        "key": API.key,
        "type": "青年漫画"
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          qingnian: res.data.result.bookList
        })
        console.log(this.data.manhua)
      }
    })
  },
  shenmei() {
    wx.request({
      url: API.book,
      data: {
        "key": API.key,
        "type": "耽美漫画"
      },
      success: (res) => {
        // console.log(res)
        this.setData({
          shenmei: res.data.result.bookList
        })
        console.log(this.data.manhua)
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})